
function Person(name, age) {
  this.name = name;
  this.age = age;
}
Person.prototype.say = function () {
  console.log(`${this.name} ${this.age}`);
};

let p1 = new Person('张三', 18);
console.log(p1.__proto__);
console.log(p1);

//深拷贝
function deppClone(obj) {
  if (typeof obj !== 'object' || obj === null) {
    return obj;
  }
  //需要拷贝的对象
  let newObj = {}
  //判断是否为数组
  if(obj instanceof Array) {
    newObj = [];
  }
  //循环拷贝
  for(let key in obj) {
    newObj[key] = deppClone(obj[key]);
  }
  return newObj;
}

let p2 = deppClone(p1);
console.log(p1=== p2);
p2.say();